﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditClientFrm.aspx.cs"
    Inherits="WebApp.EditClientFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>编辑客户信息</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript" src="js/Jquery.Query.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            initParams();
        });

        function initParams() {
            var clientId = $.query.get('ClientId');
            $('#editId').val(clientId);
            initData();
            bindClient();
            if (clientId) {
                $("#eCode").attr({ readonly: 'true' });
                $("#ePwd").attr({ readonly: 'true' });
            }
        }

        function bindClient() {
            var id = $('#editId').val();
            if (id) {
                WebApp.EditClientFrm.GetClient(id, function callback(p) {
                    if (p.error) {
                        $.messager.alert('异常消息', '获取数据异常,' + p.error.Message, 'error');
                        return;
                    }

                    var res = p.value;
                    if (res) {
                        var data = res.Data;
                        var msg = res.Msg;
                        if (msg)
                            $.messager.alert('信息获取异常', msg, 'error');
                        else {
                            if (data) {
                                $('#eShortName').val(data.shortName);
                                $('#eFullName').val(data.fullName);
                                $('#eContactMan').val(data.contactMan);
                                $('#eTel').val(data.tel);
                                $('#eFax').val(data.fax);
                                $('#eAddress').val(data.address);
                                $('#eMemo').val(data.memo);
                                $('#eBankAccount').val(data.bankAccount);
                            }
                        }
                    }
                });
            }
        }

        function initData() {
        }

        function resetFrm() {
            $('#fm').form('clear');
            $('#editId').val('');
        }

        function addClient() {
            resetFrm();
        }

        function saveClient() {
            var validate = $('#fm').form('validate');
            if (!validate)
                return;

            var id = $('#editId').val();
            var shortName = $('#eShortName').val();
            var fullName = $('#eFullName').val();
            var contactMan = $('#eContactMan').val();
            var tel = $('#eTel').val();
            var fax = $('#eFax').val();
            var address = $('#eAddress').val();
            var memo = $('#eMemo').val();
            var bankAccount = $('#eBankAccount').val();

            WebApp.EditClientFrm.SaveClient(id, shortName, fullName, contactMan, tel, fax, address, memo, bankAccount, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '提交保存异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('信息获取异常', msg, 'error');
                    else {
                        refreshParent();
                        if (id) {
                            if (data > 0) {
                                $.messager.alert('消息', '信息已更新!', 'info');
                                $('#editId').val(data);
                            }
                            else
                                $.messager.alert('信息更新异常', msg, 'error');
                        }
                        else {
                            if (data > 0) {
                                $.messager.alert('消息', '信息已创建!', 'info');
                                $('#editId').val(data);
                            }
                            else
                                $.messager.alert('信息创建异常', msg, 'error');
                        }
                    }
                }
            });
        }

        function deleteClient() {
            $.messager.confirm('提示', '确认删除该项吗?', function(r) {
                if (r) {
                    var id = $('#editId').val();
                    WebApp.EditClientFrm.DeleteClient(id, function callback(p) {

                        if (p.error) {
                            $.messager.alert('异常消息', '提交删除异常,' + p.error.Message, 'error');
                            return;
                        }
                        var res = p.value;
                        if (res) {
                            var data = res.Data;
                            var msg = res.Msg;
                            if (msg)
                                $.messager.alert('删除异常', msg, 'error');
                            else {
                                if (data == true) {
                                    $.messager.alert('消息', '信息已删除!', 'info');
                                    refreshParent();
                                }
                                else
                                    $.messager.alert('删除失败', msg, 'error');
                            }
                        }
                    });
                }
            });
        }

        function refreshParent() {
            window.parent.doSearch();
        }
    </script>

</head>
<body>
    <form id="Form1" method="post" runat="server">
    </form>
    <div>
        <form id="fm">
        <div style="padding: 5px; border: 1px solid #ddd">
            <a href="#" id="btnAdd" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="addClient()">
                新增</a> <a href="#" id="btnSave" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'"
                    onclick="saveClient()">保存</a> <a href="#" id="btnDelete" class="easyui-linkbutton"
                        data-options="plain:true,iconCls:'icon-remove'" onclick="deleteClient()">删除</a>
        </div>
        <div class="easyui-panel" title="客户资料" style="width: 500px; padding: 5px;">
            <table>
                <tr>
                    <td style="text-align: left">
                        全称：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eFullName" style="width: 150px" class="easyui-validatebox"
                            data-options="required:true" />
                    </td>
                    <td style="text-align: left">
                        简称：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eShortName" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        联系人：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eContactMan" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        联系电话：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eTel" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        传真号码：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eFax" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        银行帐号：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eBankAccount" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        联系地址：
                    </td>
                    <td style="text-align: left" colspan="3">
                        <input type="text" id="eAddress" style="width: 200px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        备注：
                    </td>
                    <td style="text-align: left" colspan="3">
                        <input type="text" id="eMemo" style="width: 200px" />
                    </td>
                </tr>
            </table>
        </div>
        <input id="editId" type="hidden" />
        </form>
    </div>
</body>
</html>
